/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * rPorArea.java
 *
 * Created on 10-feb-2012, 3:04:48
 */
package interfaz.Resultados;

import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import javax.swing.DefaultComboBoxModel;
import javax.swing.table.DefaultTableModel;
import moduloAreas.ManejadorAreas;
import pojos.Areas;
import pojos.CatReactivos;
import usoHAPSIE.HAPSIEApp;

/**
 *
 * @author ariadna
 */
public class rPorArea extends javax.swing.JDialog {
    DefaultComboBoxModel<String> modelocombo = new DefaultComboBoxModel();
    DefaultTableModel modeloTabla;
    ManejadorAreas servicioAreas = new ManejadorAreas(HAPSIEApp.servicioConexion);
    List listAreas = servicioAreas.getFullAreas();  
    
    /** Creates new form rPorArea */
    public rPorArea(java.awt.Dialog parent) {
        super(parent);
        initComponents();
        actualizaCombo();
    }
    
    public void actualizaCombo (){
        Areas temp = new Areas();
        comboEligeArea.addItem("-");
        for(int i = 0; i < listAreas.size(); i++ ){
        temp = (Areas)listAreas.get(i);  
        comboEligeArea.addItem(temp.getNombreArea());
        }
        
    }
    
    
    public LinkedList<rObjPorArea> creaListaDeResultados(){
        LinkedList<rObjPorArea> listaParaTablaRes = new LinkedList();
        Areas area;
        Set<Areas> conjRelaciones;
        for(int i = 0; i < listAreas.size(); i++){
        area = (Areas)listAreas.get(1);   
        conjRelaciones = area.getReactivos();
        }
        return listaParaTablaRes;
    }
    
    
    public void iniciaTabla(String reactivo, int calificacion){
     modeloTabla = (DefaultTableModel) tablaDeReactivos.getModel();
     Object [] fil = new Object[2];
        fil[0] = reactivo;
        fil[1] = calificacion;
        modeloTabla.addRow(fil);
        tablaDeReactivos.setModel(modeloTabla);
    }
    

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        botonSalir = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tablaDeReactivos = new javax.swing.JTable();
        comboEligeArea = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        total = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Resultados por Área");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        jLabel1.setIcon(new javax.swing.ImageIcon("C:\\Users\\ariadna\\Documents\\NetBeansProjects\\HAPSIE\\src\\interfaz\\resources\\NegotegiaIcono.png")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        botonSalir.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        botonSalir.setText("Salir");
        botonSalir.setName("botonSalir"); // NOI18N
        botonSalir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonSalirActionPerformed(evt);
            }
        });

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel2.setText("Los resultados por Área son los siguientes:");
        jLabel2.setName("jLabel2"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        tablaDeReactivos.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        tablaDeReactivos.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Reactivo", "Calificación"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.Integer.class
            };
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tablaDeReactivos.setName("tablaDeReactivos"); // NOI18N
        jScrollPane1.setViewportView(tablaDeReactivos);

        comboEligeArea.setName("comboEligeArea"); // NOI18N
        comboEligeArea.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                comboEligeAreaActionPerformed(evt);
            }
        });

        jLabel3.setText("El resultado genereal obtenido por el área es: ");
        jLabel3.setName("jLabel3"); // NOI18N

        total.setName("total"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(34, 34, 34)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 332, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 426, Short.MAX_VALUE)
                        .addComponent(jLabel1))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 552, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 12, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(157, 157, 157)
                                .addComponent(botonSalir, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(76, 76, 76)
                                .addComponent(total))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel3)
                                .addGap(34, 34, 34))))
                    .addComponent(comboEligeArea, javax.swing.GroupLayout.PREFERRED_SIZE, 527, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(50, 50, 50))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel2)
                    .addComponent(jLabel1))
                .addGap(34, 34, 34)
                .addComponent(comboEligeArea, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(49, 49, 49)
                        .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(total)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 199, Short.MAX_VALUE)
                        .addComponent(botonSalir, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(23, 23, 23))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(37, 37, 37)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 267, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void botonSalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonSalirActionPerformed
setVisible(false);
getOwner().setVisible(true);
}//GEN-LAST:event_botonSalirActionPerformed

private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
setVisible(false);
getOwner().setVisible(true);
}//GEN-LAST:event_formWindowClosing

private void comboEligeAreaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboEligeAreaActionPerformed

    int eleccion = comboEligeArea.getSelectedIndex();
    Areas area = (Areas) listAreas.get(eleccion);
    CatReactivos reactivo;
    Set reactivos = area.getReactivos();
    
    Object[] arregloDeReactivos = reactivos.toArray();
        for( int i = 0; i < arregloDeReactivos.length; i++){
          reactivo = (CatReactivos)arregloDeReactivos[i];
            
    //      iniciaTabla(reactivo.getTextoReactivo(), null);
        }
    
}//GEN-LAST:event_comboEligeAreaActionPerformed

  
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botonSalir;
    private javax.swing.JComboBox comboEligeArea;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tablaDeReactivos;
    private javax.swing.JLabel total;
    // End of variables declaration//GEN-END:variables
}
